
// <copyright file="DataStructureEnumerator.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The data structure enumerator.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System;
    using System.Collections;

    /// <summary>
    /// The data structure enumerator.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    [Serializable]
    public class DataStructureEnumerator<T> : AbstractDisposable, IKnownCountEnumerator<T>
    {
        #region Fields

        /// <summary>
        /// The data structure.
        /// </summary>
        protected IDataStructureAdapter<T> _dataStructure;

        /// <summary>
        /// The end index.
        /// </summary>
        protected int _endIndex;

        /// <summary>
        /// The index int.
        /// </summary>
        protected int _indexInt = -1;

        /// <summary>
        /// The start index int.
        /// </summary>
        protected int _startIndexInt;

        #endregion Fields

        // public DataStructureEnumerator(IDataStructureAdapter<T> dataStructure)
        // {
        // _dataStructure = dataStructure;
        // _endIndex = dataStructure.Count - 1;
        // }
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="DataStructureEnumerator{T}"/> class.
        /// </summary>
        /// <param name="dataStructure">
        /// The data structure.
        /// </param>
        /// <param name="startIndex">
        /// The start index.
        /// </param>
        /// <param name="endIndex">
        /// The end index.
        /// </param>
        public DataStructureEnumerator(IDataStructureAdapter<T> dataStructure, int startIndex, int endIndex)
        {
            this._dataStructure = dataStructure;
            this._startIndexInt = startIndex;
            this._endIndex = endIndex;
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the count.
        /// </summary>
        public int Count
        {
            get
            {
                return this._endIndex - this._startIndexInt;
            }
        }

        /// <summary>
        /// Gets the current.
        /// </summary>
        public T Current
        {
            get
            {
                return this._dataStructure[this._indexInt];
            }
        }

        #endregion Public Properties

        #region Explicit Interface Properties

        /// <summary>
        /// Gets the current.
        /// </summary>
        object IEnumerator.Current
        {
            get
            {
                return this._dataStructure[this._indexInt];
            }
        }

        #endregion Explicit Interface Properties

        #region Public Methods and Operators

        /// <summary>
        /// The move next.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public virtual bool MoveNext()
        {
            this._indexInt++;

            // while (_indexInt <= _endIndex && _indexInt < _dataStructure.Count && _dataStructure[_indexInt] == null)
            // {
            // _indexInt++;
            // }
            return this._indexInt <= this._endIndex; // && _indexInt < _dataStructure.Count;
        }

        /// <summary>
        /// The reset.
        /// </summary>
        public void Reset()
        {
            this._indexInt = this._startIndexInt - 1;
        }

        #endregion Public Methods and Operators

        #region Methods

        /// <summary>
        /// The dispose.
        /// </summary>
        /// <param name="disposing">
        /// The disposing.
        /// </param>
        protected override void Dispose(bool disposing)
        {
        }

        #endregion Methods
    }
}